package com.techyuan.algorithm.sorts;

import static com.techyuan.algorithm.utils.SortUtils.partition;

/**
 * 快速排序
 *
 * @author derek.tian on 2016/11/30.
 */
public class QuickSort implements ISort {

    public int[] sort(int[] sortingArr) {
         quickSort(sortingArr, 0, sortingArr.length - 1);
        return sortingArr;
    }

    public void quickSort(int[] sortingArr, int start, int end) {
        if (start < end) {
            int q = partition(sortingArr, start, end);
            quickSort(sortingArr, start, q - 1);
            quickSort(sortingArr, q + 1, end);
        }
    }
}
